﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InnerCalendar.aspx.cs"
    Inherits="ZX.WebApp.Crm.Hodometer.InnerCalendar" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>内训讲师行程</title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <link rel="stylesheet" href="style/StyleSheet1.css" />
    <style type="text/css">
        .style7
        {
            border-bottom: black 1px solid;
            background-color: white;
            overflow: hidden;
            height: 100%;
            width: 95%;
        }
        
        .BulletedList
        {
            margin-left: 15px;
            overflow: hidden;
            height: 100%;
            width: 95%;
            line-height: 25px;
        }
    </style>
    <script language="javascript" type="text/javascript">

        function $$(v) { return document.getElementById(v); }

        function ReviewForm(obj) {
            //空值隐藏
            var strs = null;
            var arr = new Array("MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Orange", "PowderBlue", "Blue", "Tan", "Transparent", "Yellow", "SeaGreen", "Snow", "Teal", "LightBlue", "LightCoral", "LightCyan", "LightGoldenrodYellow", "LightGray", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray", "LightSteelBlue", "LightYellow");

            if (obj != null && obj != "") {
                strs = obj.split(';');
            }
            for (var i = 1; i < 7; i++) {
                var tb = $$("tb" + i + i + "0");
                if (tb != null)
                    tb.style.visibility = "hidden";
            }
            //周末变色
            var sp1 = $$("sp1");
            if (sp1 != null)
                sp1.style.color = "red";
            for (var i = 7; i < 36; i++) {
                if (i % 7 == 0) {
                    var sp = $$("sp" + i);
                    var sp1 = $$("sp" + (i + 1));
                    if (sp != null)
                        sp.style.color = "red";
                    if (sp1 != null)
                        sp1.style.color = "red";
                }
            }

            for (var j = 1; j < 32; j++) {
                var taa = $$("Ta" + j);

                setValue(taa);

                if (strs != null && strs != "") {
                    //底色变化
                    for (var k = 0, l = strs.length; k < (l - 1); k++) {
                        if (taa == null)
                            break;
                        if (contains(taa.value, strs[k], true)) {
                            taa.style.backgroundColor = arr[k];
                        }
                    }
                }
            }
        }

        //删除字符串左边的空格 
        function ltrim(str) {
            if (str.length == 0)
                return (str);
            else {
                var idx = 0;
                while (str.charAt(idx).search(/\s/) == 0)
                    idx++;
                return (str.substr(idx));
            }
        }

        //删除字符串右边的空格 
        function rtrim(str) {
            if (str.length == 0)
                return (str);
            else {
                var idx = str.length - 1;
                while (str.charAt(idx).search(/\s/) == 0)
                    idx--;
                return (str.substring(0, idx + 1));
            }
        }

        //删除字符串左右两边的空格 
        function trim(str) {
            return (rtrim(ltrim(str)));
        } 


        function getCalendar(obj) {
            if (obj.value.indexOf('--') == -1) {
                var next;
                var n = obj;
                do n = n.nextSibling;
                while (n && n.nodeType != 1);
                next = $$(n.id);
                var nowdate = '<%= RebackDate %>';
                var d = obj.id.substring(2)
                var ym = $$("dl_Calendar_lab_Time");
                var ddl = $$("dl_Calendar_ddlteach");
                var teaid = '<%= SelectTea %>';
                var dated = ym.innerHTML + "-" + d;
                if (trim(obj.value) == "") {
                    obj.style.backgroundColor = "White";
                } else {
                    obj.style.backgroundColor = "Green";
                }
                $.post("NewInCalendar.ashx", { HID: "", orderid: "00000000-0000-0000-0000-000000000000", sttime: dated, edtime: dated, tchid: teaid, reason: trim(obj.value), color: "Green" }, function (data) {
                    pross(data, d, teaid);
                });
            }
        }
        function pross(obj, d, teaid) {
            if (obj == 1) {
                myrefresh(teaid);
            }
        }
        function setValue(ta) {
            if (ta != null && ta.value != "") {
                var hdcid = getnextnextobj(ta);
                var hdfbc = getnextobj(hdcid);
                if (ta.value.indexOf('</br>(') > -1) {
                    var val = ta.value.split('(');
                    var oLink = document.createElement("a");
                    oLink.href = "#";
                    oLink.id = hdcid.value;
                    oLink.onclick = (function pop() { hrefModify(hdcid.value); });
                    oLink.innerHTML = "<font  color=blue>" + val[0] + "</font>";
                    ta.value = "";
                    var oL = document.createElement("a");
                    oL.innerHTML = "(" + val[1];
                    ta.appendChild(oLink);
                    ta.appendChild(oL);
                }
                ta.style.backgroundColor = hdfbc.value;
            }
        }
        //链接跳到查看客户信息
        function hrefModify(id) {
            var temAvail = "<%=getRoleCondition() %>";
            if (temAvail.length > 1) {
                var own = temAvail.substr(0, 1);
                var ownName = temAvail.substr(1, temAvail.length - 1);
                if (own == "0") {
                    if (ownName != document.getElementById("dl_Calendar_Labteacher").innerHTML) {
                        alert("您暂时无权查看该客户信息");
                        return;
                    }
                }
            }
            var pagetitle = "查看客户信息";
            parent.$("#tabs").tabs('close', pagetitle);
            parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?entity=CrmCustomer&title=' + encodeURI(pagetitle) + '&id=' + id);

        }
        function getnextnextobj(obj) {
            var n = obj; //$$("Tasw11");
            var next;
            do n = n.nextSibling;
            while (n && n.nodeType != 1);
            next = n.id;

            var n1 = $$(next);
            do n1 = n1.nextSibling;
            while (n1 && n1.nodeType != 1);
            //alert(n1.id);
            return n1;
        }
        function getnextobj(obj) {
            var n = obj; //$$("Tasw11");
            var next;
            do n = n.nextSibling;
            while (n && n.nodeType != 1);
            return n;
        }
        // string:原始字符串
        //substr:子字符串
        //isIgnoreCase:忽略大小写
        function contains(string, substr, isIgnoreCase) {
            if (isIgnoreCase) {
                string = string.toLowerCase();
                substr = substr.toLowerCase();
            }
            var startChar = substr.substring(0, 1);
            var strLen = substr.length;
            for (var j = 0; j < string.length - strLen + 1; j++) {
                if (string.charAt(j) == startChar)  //如果匹配起始字符,开始查找
                {
                    if (string.substring(j, j + strLen) == substr)  //如果从j开始的字符与str匹配，那ok
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        function myrefresh(obj) {

            var currenturl = window.location.href;
            if (currenturl.indexOf("&Setea") >= 0) {
                currenturl = currenturl.substring(0, currenturl.indexOf("&Setea"));
            }

            if (obj != undefined && obj != "")
                obj = "&Setea=" + obj;
            else
                obj = "";
            window.location.href = currenturl + obj;
            //alert(window.location.href);
            //window.location.reload(); 
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="background: #F2F2F2; min-height: 560px;">
        <div id="Left" class="calendar-container" style="width: 8%; min-height: 600px; background-color: #F2F2F2;
            font-size: medium; float: left;">
            <p style="margin-top: 5px; color: Black;">
                讲师：</p>
            <asp:BulletedList ID="blInnerTeacher" runat="server" CssClass="BulletedList" DisplayMode="LinkButton"
                OnClick="blInnerTeacher_OnClick" BorderColor="#99CCFF">
            </asp:BulletedList>
            <br />
        </div>
        <div id="right" style="width: 92%; float: right;">
            <div class="calendar-container" id="calendar-container">
                <asp:DataList ID="dl_Calendar" Width="100%" runat="server" BorderColor="#99CCFF"
                    BorderWidth="1px" CellPadding="1" GridLines="Both" RepeatColumns="7" RepeatDirection="Horizontal"
                    OnItemDataBound="dl_Calendar_ItemDataBound">
                    <HeaderTemplate>
                        <table style="width: 100%; line-height: 35px; text-align: center;" border="0">
                            <tr>
                                <td style="width: 14%; text-align: right; font-size: medium;">
                                    当前讲师：
                                </td>
                                <td style="width: 14%; text-align: left;">
                                    <asp:Label ID="Labteacher" runat="server" Text=""></asp:Label>
                                </td>
                                <td style="width: 15%; text-align: right; font-size: x-large; font-weight: bolder;">
                                    <asp:LinkButton ID="lbtnYearPre" runat="server" Font-Underline="false" CssClass="Edit"
                                        CommandName="PreY" OnCommand="dl_Command" Text="<<"></asp:LinkButton>&nbsp;&nbsp;&nbsp;
                                    <asp:LinkButton ID="btn_Edit" runat="server" Font-Underline="false" CssClass="Edit"
                                        CommandName="Pre" OnCommand="dl_Command" Text="<"></asp:LinkButton>
                                </td>
                                <td style="width: 14%; text-align: center; font-size: x-large; font-weight: bolder;">
                                    <asp:Label runat="server" ForeColor="blue" ID="lab_Time"></asp:Label>
                                </td>
                                <td style="width: 15%; text-align: left; font-size: x-large; font-weight: bolder;">
                                    <asp:LinkButton ID="lbtnMonthNext" runat="server" CssClass="Edit" Font-Underline="false"
                                        CommandName="Next" OnCommand="dl_Command" Text=">"></asp:LinkButton>&nbsp;&nbsp;&nbsp;
                                    <asp:LinkButton ID="lbtnYearNext" runat="server" Font-Underline="false" CssClass="Edit"
                                        CommandName="NextY" OnCommand="dl_Command" Text=">>"></asp:LinkButton>
                                </td>
                                <td style="width: 28%;" colspan="2">
                                    <span style="font-size: small; font-weight: lighter; line-height: 18px;">* 显示格式：<br />
                                        客户名(理由)</span>
                                </td>
                            </tr>
                            <tr style="padding: 1px; border-top: 1px solid #b8cede; font-size: x-large; font-weight: bolder;">
                                <td style="color: Red; text-align: center;">
                                    <span>日</span>
                                </td>
                                <td style="text-align: center;">
                                    <span>一</span>
                                </td>
                                <td style="text-align: center;">
                                    <span>二</span>
                                </td>
                                <td style="text-align: center;">
                                    <span>三</span>
                                </td>
                                <td style="text-align: center;">
                                    <span>四</span>
                                </td>
                                <td style="text-align: center;">
                                    <span>五</span>
                                </td>
                                <td style="color: Red; text-align: center;">
                                    <span>六</span>
                                </td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <table id="tb<%#Eval("DTime") %>" cellpadding="0" cellspacing="0" style="width: 100%;
                            visibility: visible;">
                            <tr>
                                <td style="text-align: center; font-size: x-large; font-weight: bold;">
                                    <span id="sp<%#Eval("Nums") %>">
                                        <%#Eval("DTime") %></span>
                                </td>
                            </tr>
                            <tr style="padding: 1px; border-top: 1px solid #b8cede;">
                                <td style="width: 90%;">
                                    <textarea id="Ta<%#Eval("DTime") %>" title='<%#getReplace(Eval("Cusname")) %>' rows="4"
                                        ondblclick="tadbclick(this)" class="style7" onchange="getCalendar(this)"><%#getShortName(Eval("Cusname"))%></textarea>
                                    <asp:HiddenField runat="server" ID="hdfid" Value='<%#Eval("ID") %>' />
                                    <asp:HiddenField runat="server" ID="hdfcusid" Value='<%#Eval("Cusid") %>' />
                                    <asp:HiddenField runat="server" ID="hdfbc" Value='<%#Eval("BackColor") %>' />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    <ItemStyle Width="14%" />
                </asp:DataList>
            </div>
            <div id="dialog1" class="yui-pe-content">
                <div class="hd">
                    客户选择</div>
                <div class="bd">
                    <iframe id="EditUIWindow" frameborder="0" src="" style="width: 100%; height: 100%;
                        margin: 0px; padding: 0px;"></iframe>
                </div>
            </div>
            <script language="javascript" type="text/javascript">
                YAHOO.namespace("example.container");
                YAHOO.util.Event.onDOMReady(function () {
                    var handleSubmit = function () {
                        var editwindow = document.getElementById("EditUIWindow");
                        if (editwindow) {
                            editwindow.contentWindow.Save();
                        }
                        this.cancel();
                    };
                    var handleCancel = function () {
                        this.cancel();
                    };
                    var handleFailure = function (o) {
                        alert("Submission failed: " + o.status);
                    };
                    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
							        { width: "750px",
							            height: "500px",
							            fixedcenter: true,
							            visible: false,
							            draggable: true,
							            close: true,
							            autofillheight: "body",
							            constraintoviewport: true,
							            buttons: [{ text: "保存", handler: handleSubmit, isDefault: true },
								      { text: "取消", handler: handleCancel}]
							        });
                    YAHOO.example.container.dialog1.render();
                });

                function tadbclick(obj) {
                    var next;
                    var n = obj;
                    do n = n.nextSibling;
                    while (n && n.nodeType != 1);
                    next = $$(n.id);
                    if (queryString("TYPE") == null) {//新增讲师行程
                        var nowdate = '<%= RebackDate %>';
                        var d = obj.id.substring(2)
                        var ym = $$("dl_Calendar_lab_Time");
                        var ddl = $$("dl_Calendar_ddlteach");
                        var teaid = '<%= SelectTea %>';
                        var dated = ym.innerHTML + "-" + d;
                        //                if ((new Date(nowdate.replace(/-/g, "/"))) > (new Date(dated.replace(/-/g, "/")))) {
                        //                    alert("改行程日期已过去，不能新增或修改！");
                        //                    return false;
                        //                }
                        var SelectTea = "<%=SelectTea %>";
                        parent.addTabs('新增讲师行程', '../Crm/Hodometer/NewInCalendar.aspx?HID=' + next.value + '&TA=' + obj.id + '&Setea=' + SelectTea + '&HD=' + n.id + '&TEAID=' + teaid + '&DATED=' + dated);
                        parent.NeedRefreshPage = this;
                    }
                    else {//讲师行程总结
                        if (next.value != "") {
                            var temAvail = "<%=getRoleCondition() %>";
                            if (temAvail.length > 1) {
                                var own = temAvail.substr(0, 1);
                                var ownName = temAvail.substr(1, temAvail.length - 1);
                                if (own == "0") {
                                    if (ownName != document.getElementById("dl_Calendar_Labteacher").innerHTML) {
                                        alert("您暂时无权填写该讲师内训总结");
                                        return;
                                    }
                                }
                            }
                            parent.addTabs('讲师内训总结', '../Crm/Hodometer/InCalendarSum.aspx?HDID=' + next.value + "&TNAME=" + document.getElementById("dl_Calendar_Labteacher").innerHTML);
                            parent.NeedRefreshPage = this;
                        }
                    }
                }
                //只取一个URL参数：
                var queryString = function (key) {
                    return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
                }
                $(document).ready(function () {
                    if (queryString("TYPE") != null || queryString("TYPE") == "1") {
                        for (var j = 1; j < 32; j++) {
                            var taa = $("#Ta" + j);
                            taa.attr('readonly', "true")
                        }
                    }
                });
            </script>
        </div>
    </div>
    </form>
</body>
</html>
